package logic

import (
	"context"
	"gorm.io/gorm"
	"zhihu/models/mysql"

	"zhihu/zhihuRpc/internal/svc"
	"zhihu/zhihuRpc/zhihuRpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PrefectLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPrefectLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PrefectLogic {
	return &PrefectLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PrefectLogic) Prefect(in *zhihuRpc.PrefectRequest) (*zhihuRpc.PrefectResponse, error) {
	// todo: add your logic here and delete this line

	user := mysql.User{
		Model:    gorm.Model{ID: uint(in.UserId)},
		Image:    in.Image,
		NickName: in.NickName,
		Sex:      in.Sex,
		Info:     in.Info,
		Ads:      in.Ads,
	}

	mysql.DB.Updates(&user)

	return &zhihuRpc.PrefectResponse{
		UserId: int64(user.ID),
	}, nil
}
